package com.authine.cloudpivot.web.api.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * ClassName: DateUtils <br/>
 * Description: 时间工具类<br/>
 * date: 2020/8/25 14:03<br/>
 * @author fj<br />
 * @since JDK 1.8
 */
public class DateUtils {

    /**
     * Description: 基于指定日期增加或减少小时数，正数增加，负数减少
     * @Param: [date, num]
     * @Author: fj
     * @Date: 2020/8/25
     * @Return: java.util.Date
     */
    public static Date addDay(Date date, int num){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR,num);
        return calendar.getTime();
    }

    /**
     * Description:获取当前时间
     * @Param: []
     * @Author: fj
     * @Date: 2020/8/25
     * @Return: java.lang.String
     */
    public static String getNow(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowTime = format.format(new Date());
        return nowTime;
    }
    /**
     * Description: 获取指定日期的年份
     * @Param: [date]
     * @Author: fj
     * @Date: 2020/8/25
     * @Return: java.lang.String
     */
    public static String getYear(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy");
        String year = format.format(date);
        return year;
    }
}
